// pages/record/record.js
Page({

    data: {
        listIndex:[],
        reverselist:[],
        list:[]
    },
    onLoad: function (options) {
        var that = this;
        wx.request({
          url: 'http://api.heclouds.com/devices/716616050/datapoints',
          data: {
            datastream_id: 'timer',
            start: '2021-05-17T00:00:00'
          },
          header: {
            'content-type': 'application/json',
            'api-key':'dZcn2Vn5AXHpcPON2604FVia7wk='
          },
          success(res){
            var count = res.data.data.count;
            var arr = res.data.data.datastreams[0].datapoints;
            //console.log(count);
            //console.log(arr);
            var mod = 3-count%3;
            for(var a=0;a<mod;a++){
              //arr[count+a]={"show":false};
              arr[count+a]={
                timer:"00:00",
                at:"00-00",
                value:true,
                show:false
              }
            }
            arr = arr.reverse();
            console.log(arr)
            var index;
            for(index=mod;index<count+mod;index++){
              // arr[index].timer=arr[index].at.substr(10,6)
              // arr[index].at=arr[index].at.substr(5,5),
              // arr[index].value=arr[index].value=="1"?true:false
              arr[index]={
                timer:arr[index].at.substr(10,6),
                at:arr[index].at.substr(5,5),
                value:arr[index].value=="1"?true:false,
                show:true
              }
            }

            var i = 0, j = 0,k = 0;
            while(i<count){
                var temp =[
                    arr[i++],
                    arr[i++],
                    arr[i++]
                ]
                that.setData({
                  ["list["+ j++ +"]"]:temp
                })
            }
            
            console.log(that.data.list)
          }
        })
    }
})